import axios from 'axios';
import { useRouter } from 'vue-router';
import { ElMessage } from 'element-plus';
const router = useRouter();
axios.defaults.headers['Content-Type'] = 'application/json;charset=utf-8';
// 对应国际化资源文件后缀
axios.defaults.headers['Content-Language'] = 'zh_CN';
// 创建axios实例
const service = axios.create({
	// axios中请求配置有baseURL选项，表示请求URL公共部分
	baseURL: '/api',
	// 超时
	timeout: 10000,
});

service.interceptors.response.use((res) => {
	let { data } = res;
	console.log('data', data);
	if (data.code && data.code == '500') {
		ElMessage({
			message: data.msg,
			type: 'error',
		});
		return Promise.reject('请求异常');
	} else {
		return res.data;
	}
});
export default service;
